//
//  ZYMainViewController.swift
//  CZ29WeiboZYH
//
//  Created by 沐颜澈 on 16/6/23.
//  Copyright © 2016年 muyanche. All rights reserved.
//

import UIKit

class ZYMainViewController: UITabBarController {
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        
        //自定义一个tabbar,委托let tabBar = ZYTabbar() 弹出
        let tabBar = ZYTabbar()
        setValue(tabBar, forKey: "tabBar")
        
        //1.设置代理
        tabBar.zyDelegate = self
        
        //设置颜色要
        addChildViewController(ZYHomeTableViewController(),title: "首页", imagName: "tabbar_home")
        addChildViewController(ZYMessageTableViewController(),title: "消息", imagName: "tabbar_message_center")
        addChildViewController(ZYDiscoveryTableViewController(),title: "发现", imagName: "tabbar_discover")
        addChildViewController(ZYProfileTableViewController(),title: "我的", imagName: "tabbar_profile")

        
    }
    
    func addChildViewController(vc: UIViewController, title: String, imagName: String) {
        
        //tabbar_home_selected   (图片)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imagName)
        vc.tabBarItem.selectedImage = UIImage(named:"\(imagName)_selected")
        //另外加上一个导航栏
        let navc = UINavigationController(rootViewController: vc)
        //把子控制器添加到主控制器
        addChildViewController(navc)
        
    }
    
}


//实现代理方法
extension ZYMainViewController: ZYTabBarDelegate {
    func composeButtonClick() {
        print("弹出控制器")
        let nav = UINavigationController(rootViewController: ZYComposeViewController())
        
        presentViewController(nav, animated: true, completion: nil)
        
        
    }

}

